package cn.shopping.core.mapper;

import cn.shopping.common.mapper.CommonMapper;
import cn.shopping.core.dbo.GoodsDO;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;



/**
 * 代码自动生成，请不要修改，切记！！！
 */
@Mapper
public interface GoodsMapper extends CommonMapper<GoodsDO,Long> {

        public List<GoodsDO> listByTitle(@Param("title") String title,@Param("fieldNames") String[] fieldNames);

        @MapKey("id")
        public Map<Long,GoodsDO> mapByTitle(@Param("title") String title,@Param("fieldNames") String[] fieldNames);

        public Integer countByTitle(@Param("title") String title);

        public default GoodsDO singleResultByTitle(String title,String[] fieldNames){
             List<GoodsDO> list=this.listByTitle(title,fieldNames);
             return CollectionUtils.isEmpty(list)?null:list.get(0);
        }

         public default <T> Map<T,List<GoodsDO>> groupingByTitle(String title, Function<GoodsDO, T> mapper, String[] fieldNames){
             List<GoodsDO> list=this.listByTitle(title,fieldNames);
             if(CollectionUtils.isEmpty(list)){
                return new HashMap<>();
             }
             return list.stream().collect(Collectors.groupingBy(mapper));
         }

        public Integer updateNotNullFieldsByTitle(@Param("updateDO") GoodsDO updateDO, @Param("title") String title);

        public Integer updateAllFieldsByTitle(@Param("updateDO") GoodsDO updateDO, @Param("title") String title);

        public Integer deleteByTitle( @Param("title") String title);




        public List<GoodsDO> listByInTitle(@Param("titleList") Collection<String> titleList,@Param("fieldNames") String[] fieldNames);

        @MapKey("id")
        public Map<Long,GoodsDO> mapByInTitle(@Param("titleList") Collection<String> titleList,@Param("fieldNames") String[] fieldNames);

        public Integer countByInTitle(@Param("titleList") Collection<String> titleList);

        public default GoodsDO singleResultByInTitle(Collection<String> titleList,String[] fieldNames){
             List<GoodsDO> list=this.listByInTitle(titleList,fieldNames);
             return CollectionUtils.isEmpty(list)?null:list.get(0);
        }

         public default <T> Map<T,List<GoodsDO>> groupingByInTitle(Collection<String> titleList, Function<GoodsDO, T> mapper, String[] fieldNames){
             List<GoodsDO> list=this.listByInTitle(titleList,fieldNames);
             if(CollectionUtils.isEmpty(list)){
                return new HashMap<>();
             }
             return list.stream().collect(Collectors.groupingBy(mapper));
         }

        public Integer updateNotNullFieldsByInTitle(@Param("updateDO") GoodsDO updateDO, @Param("titleList") Collection<String> titleList);

        public Integer updateAllFieldsByInTitle(@Param("updateDO") GoodsDO updateDO, @Param("titleList") Collection<String> titleList);

        public Integer deleteByInTitle( @Param("titleList") Collection<String> titleList);

        public List<GoodsDO> listByDescribe(@Param("describe") String describe,@Param("fieldNames") String[] fieldNames);

        @MapKey("id")
        public Map<Long,GoodsDO> mapByDescribe(@Param("describe") String describe,@Param("fieldNames") String[] fieldNames);

        public Integer countByDescribe(@Param("describe") String describe);

        public default GoodsDO singleResultByDescribe(String describe,String[] fieldNames){
             List<GoodsDO> list=this.listByDescribe(describe,fieldNames);
             return CollectionUtils.isEmpty(list)?null:list.get(0);
        }

         public default <T> Map<T,List<GoodsDO>> groupingByDescribe(String describe, Function<GoodsDO, T> mapper, String[] fieldNames){
             List<GoodsDO> list=this.listByDescribe(describe,fieldNames);
             if(CollectionUtils.isEmpty(list)){
                return new HashMap<>();
             }
             return list.stream().collect(Collectors.groupingBy(mapper));
         }

        public Integer updateNotNullFieldsByDescribe(@Param("updateDO") GoodsDO updateDO, @Param("describe") String describe);

        public Integer updateAllFieldsByDescribe(@Param("updateDO") GoodsDO updateDO, @Param("describe") String describe);

        public Integer deleteByDescribe( @Param("describe") String describe);




        public List<GoodsDO> listByInDescribe(@Param("describeList") Collection<String> describeList,@Param("fieldNames") String[] fieldNames);

        @MapKey("id")
        public Map<Long,GoodsDO> mapByInDescribe(@Param("describeList") Collection<String> describeList,@Param("fieldNames") String[] fieldNames);

        public Integer countByInDescribe(@Param("describeList") Collection<String> describeList);

        public default GoodsDO singleResultByInDescribe(Collection<String> describeList,String[] fieldNames){
             List<GoodsDO> list=this.listByInDescribe(describeList,fieldNames);
             return CollectionUtils.isEmpty(list)?null:list.get(0);
        }

         public default <T> Map<T,List<GoodsDO>> groupingByInDescribe(Collection<String> describeList, Function<GoodsDO, T> mapper, String[] fieldNames){
             List<GoodsDO> list=this.listByInDescribe(describeList,fieldNames);
             if(CollectionUtils.isEmpty(list)){
                return new HashMap<>();
             }
             return list.stream().collect(Collectors.groupingBy(mapper));
         }

        public Integer updateNotNullFieldsByInDescribe(@Param("updateDO") GoodsDO updateDO, @Param("describeList") Collection<String> describeList);

        public Integer updateAllFieldsByInDescribe(@Param("updateDO") GoodsDO updateDO, @Param("describeList") Collection<String> describeList);

        public Integer deleteByInDescribe( @Param("describeList") Collection<String> describeList);

        public List<GoodsDO> listByPrice(@Param("price") Double price,@Param("fieldNames") String[] fieldNames);

        @MapKey("id")
        public Map<Long,GoodsDO> mapByPrice(@Param("price") Double price,@Param("fieldNames") String[] fieldNames);

        public Integer countByPrice(@Param("price") Double price);

        public default GoodsDO singleResultByPrice(Double price,String[] fieldNames){
             List<GoodsDO> list=this.listByPrice(price,fieldNames);
             return CollectionUtils.isEmpty(list)?null:list.get(0);
        }

         public default <T> Map<T,List<GoodsDO>> groupingByPrice(Double price, Function<GoodsDO, T> mapper, String[] fieldNames){
             List<GoodsDO> list=this.listByPrice(price,fieldNames);
             if(CollectionUtils.isEmpty(list)){
                return new HashMap<>();
             }
             return list.stream().collect(Collectors.groupingBy(mapper));
         }

        public Integer updateNotNullFieldsByPrice(@Param("updateDO") GoodsDO updateDO, @Param("price") Double price);

        public Integer updateAllFieldsByPrice(@Param("updateDO") GoodsDO updateDO, @Param("price") Double price);

        public Integer deleteByPrice( @Param("price") Double price);




        public List<GoodsDO> listByInPrice(@Param("priceList") Collection<Double> priceList,@Param("fieldNames") String[] fieldNames);

        @MapKey("id")
        public Map<Long,GoodsDO> mapByInPrice(@Param("priceList") Collection<Double> priceList,@Param("fieldNames") String[] fieldNames);

        public Integer countByInPrice(@Param("priceList") Collection<Double> priceList);

        public default GoodsDO singleResultByInPrice(Collection<Double> priceList,String[] fieldNames){
             List<GoodsDO> list=this.listByInPrice(priceList,fieldNames);
             return CollectionUtils.isEmpty(list)?null:list.get(0);
        }

         public default <T> Map<T,List<GoodsDO>> groupingByInPrice(Collection<Double> priceList, Function<GoodsDO, T> mapper, String[] fieldNames){
             List<GoodsDO> list=this.listByInPrice(priceList,fieldNames);
             if(CollectionUtils.isEmpty(list)){
                return new HashMap<>();
             }
             return list.stream().collect(Collectors.groupingBy(mapper));
         }

        public Integer updateNotNullFieldsByInPrice(@Param("updateDO") GoodsDO updateDO, @Param("priceList") Collection<Double> priceList);

        public Integer updateAllFieldsByInPrice(@Param("updateDO") GoodsDO updateDO, @Param("priceList") Collection<Double> priceList);

        public Integer deleteByInPrice( @Param("priceList") Collection<Double> priceList);


}
